<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 实现三个按钮 点击每个按钮显示对应div ，且 按钮会加上背景颜色，也就是指点现在点击的是哪个按钮
        window.onload = function () {
            var btns = document.querySelectorAll("button");
            var divs = document.querySelectorAll("div");
            btns.forEach(function (btn, key) {
                // console.log(btn);
                btn.onclick = function () {
                    divs.forEach(function (div, index) {
                        if (key === index) {
                            // 点击的按钮和 当前的div 索引一致 ；
                            div.style.display = "block";
                        } else {
                            // 剩余的和 点击的key 不同的div
                            div.style.display = "none";
                        }

                    })

                }
            })
        }
    </script>
    <style>
        div {
            width: 50px;
            height: 50px;
            display: none;
        }

        .box1 {
            /* display: block; */
            background-color: red;
        }

        .box2 {
            /* display: block; */
            background-color: blue;
        }

        .box3 {
            /* display: block; */
            background-color: yellow;
        }
    </style>
</head>

<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <!-- <input type="text"> -->
    <button class="btn1">添加1</button>
    <button class="btn2">添加2</button>
    <button class="btn3">添加3</button>
</body>

</html>